﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace ProjectNocturnalFool
{
    class PartyMemberPanel : PanelControl
    {
        public int characterIndex = 0;
        public Color selectBorderColor = Color.DarkKhaki;
        public ButtonControl portrait;

        public override void LoadContent()
        {
            base.LoadContent();

            bgTint = Color.LightSteelBlue;

            height = 80;
            width = 40;
            
            portrait = new ButtonControl();
            portrait.LoadContent();
            portrait.bgTexture = IconLoader.loadRaceIcon(GameLogic.Instance.gameCharacterSession.charList[characterIndex].charRace);
            portrait.yAnchor = VerticleAnchor.Top;
            portrait.xAnchor = HorizontalAnchor.Middle;
            portrait.type = Button_Type.PartySelectPortrait;
            portrait.y = y + Constants.ControlSmallOffsets;
            portrait.x = Util.getCentreDrawPointX(x, width, portrait.width);
            portrait.style = Button_Style.Image;
            portrait.borderColor = Color.Black;
            portrait.borderSize = 1;
            portrait.active = false;
            controls.Add(portrait);

            int prevSpace = Constants.ControlSmallOffsets + (portrait.height + portrait.y);

            ButtonControl editBtn = new ButtonControl();
            editBtn.LoadContent();
            editBtn.yAnchor = VerticleAnchor.Top;
            editBtn.xAnchor = HorizontalAnchor.Middle;
            editBtn.type = Button_Type.PortraitEdit;
            editBtn.width = 36;
            editBtn.height = Constants.PortraitButtonHeight;
            editBtn.x = x + Constants.ControlSmallOffsets;
            editBtn.y = prevSpace;
            prevSpace += editBtn.height + Constants.ControlSmallOffsets;
            controls.Add(editBtn);

            editBtn = new ButtonControl();
            editBtn.LoadContent();
            editBtn.yAnchor = VerticleAnchor.Top;
            editBtn.xAnchor = HorizontalAnchor.Middle;
            editBtn.type = Button_Type.PortraitLoad;
            editBtn.width = 36;
            editBtn.height = Constants.PortraitButtonHeight;
            editBtn.x = x + Constants.ControlSmallOffsets;
            editBtn.y = prevSpace;
            prevSpace += editBtn.height + Constants.ControlSmallOffsets;
            controls.Add(editBtn);

            editBtn = new ButtonControl();
            editBtn.LoadContent();
            editBtn.yAnchor = VerticleAnchor.Top;
            editBtn.xAnchor = HorizontalAnchor.Middle;
            editBtn.type = Button_Type.PortraitRandom;
            editBtn.width = 36;
            editBtn.height = Constants.PortraitButtonHeight;
            editBtn.x = x + Constants.ControlSmallOffsets;
            editBtn.y = prevSpace;
            editBtn.font.Spacing = 0;
            prevSpace += editBtn.height + Constants.ControlSmallOffsets;
            controls.Add(editBtn);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            portrait.bgTexture = IconLoader.loadRaceIcon(GameLogic.Instance.gameCharacterSession.charList[characterIndex].charRace);
        }

        public override void HandleHover()
        {
            base.HandleHover();
            updateStatus.Add(Tuple.Create(typeof(PartyMemberPanel).Name, characterIndex, 0));
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            Rectangle targetRect = new Rectangle(x, y, width, height);

            TacticsGame.Instance.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);
            
            if (Hover)
                Util.drawBorder(targetRect, selectBorderColor, 1);
            else
                Util.drawBorder(targetRect, borderColor, 1);

            TacticsGame.Instance.spriteBatch.End();

        }
    }
}
